﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

/// <summary>
/// 字符串操作类
/// </summary>
public class Class_String
{
    /// <summary>
    /// 从字符串Source中Start_Keyword处截取到End_Keyword处 返回的字符串是否包含开始关键字 是否包含结尾关键字
    /// </summary>
    /// <param name="Source">源字符串</param>
    /// <param name="Start_Keyword">开始截取位置字符串 为空从头截取</param>
    /// <param name="End_Keyword">结束截取字符串 为空截取到尾</param>
    /// <param name="Is_IncludeStart">是否包含开头关键字</param>
    /// <param name="Is_IncludeEnd">是否包含尾部关键字</param>
    /// <returns></returns>
    public static string Mid(string Source, string Start_Keyword, string End_Keyword, bool Is_IncludeStart, bool Is_IncludeEnd)
    {
        Int32 Key_S = 0;
        if (Start_Keyword != "")
        {
            Key_S = Source.IndexOf(Start_Keyword);
            if (Key_S == -1) { return ""; }
            if (!Is_IncludeStart)
            {
                Key_S = Key_S + Start_Keyword.Length;
            }
        }
        else
        {
            Key_S = 0;
        }
        Int32 Key_E = 0;
        if (End_Keyword != "")
        {
            Key_E = Source.IndexOf(End_Keyword, Key_S);
            if (Key_E == -1) { return ""; }
            if (Is_IncludeEnd)
            {
                Key_E = Key_E + End_Keyword.Length;
            }
        }
        else
        {
            Key_E = Source.Length;
        }

        return Source.Substring(Key_S, Key_E - Key_S);

    }

}